/*******************************************************************************
* FileName:         SeqStack.cpp
* Author:           李智铭
* Student Number:   3022206093
* Date:             2024/10/23 15：25：00
* Version:          v1.0
* Description:      Data Structure Experiment #3
*******************************************************************************/
#include "SeqStack.h"
#include <iostream>
#include <stdexcept>

SeqStack::SeqStack(){
    SeqList = new int[MAX_ELEMENTS];
    data_top = -1;     //初始化栈顶为-1
}
SeqStack::~SeqStack(){
    delete[] SeqList;      //释放内存
}
void SeqStack::push_back(int data){
    if(data_top >= MAX_ELEMENTS - 1){     //判定栈溢出情况
        throw std :: overflow_error("STACK OVERFLOW");
    }
    SeqList[++data_top] = data;     //栈顶+1
}
int SeqStack::top() const{
    if(data_top == -1){     //判定栈空情况
        throw std :: underflow_error("EMPTY STACK");
    }
    return SeqList[data_top];
}
void SeqStack::pop(){
    if(data_top == -1){     //判定栈空情况
        throw std :: underflow_error("EMPTY STACK");
    }
    data_top--;     //栈顶-1
}